﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Xml;

namespace CodeSnippetsEditor
{
    public class ClassCode
    {
        private XmlNode codeNode = null;
        private string language = string.Empty;
        private string kind = string.Empty;
        private string delimiter = string.Empty;

        /// <summary>
        /// Initializes a new instance of the <see cref="ClassCode"/> class.
        /// </summary>
        public ClassCode()
        {
            XmlDocument doc = new XmlDocument();
            codeNode = doc.CreateNode(XmlNodeType.CDATA, "Code", string.Empty);        
        }

        /// <summary>
        /// Gets or sets the code.
        /// </summary>
        /// <value>The code.</value>
        [XmlIgnore]
        public string Code
        {
            get
            {
                return (codeNode == null ? string.Empty : codeNode.Value);
            }
            set
            {
                XmlDocument doc = new XmlDocument();
                codeNode = doc.CreateNode(XmlNodeType.CDATA, "Code", string.Empty);

                codeNode.Value = value;
            }
        }

        /// <summary>
        /// Gets or sets the C data code.
        /// </summary>
        /// <value>The C data code.</value>
        [XmlAnyElement()]
        public XmlNode CodeNode
        {
            get
            {
                return codeNode;
            }
            set
            {
                codeNode = value;
            }
        }

        /// <summary>
        /// Gets or sets the language.
        /// </summary>
        /// <value>The language.</value>
        [XmlAttribute()]
        public string Language
        {
            get
            {
                return language;
            }
            set
            {
                language = value;
            }
        }

        /// <summary>
        /// Gets or sets the kind.
        /// </summary>
        /// <value>The kind.</value>
        [XmlAttribute()]
        public string Kind
        {
            get
            {
                return kind;
            }
            set
            {
                kind = value;
            }
        }

        /// <summary>
        /// Gets or sets the delimiter.
        /// </summary>
        /// <value>The delimiter.</value>
        [XmlAttribute()]
        public string Delimiter
        {
            get
            {
                return delimiter;
            }
            set
            {
                delimiter = value;
            }
        }
    }
}
